import { IObserver, INotification } from "../../Interfaces";

export class Observer implements IObserver {
  private notify: Function = null;
  private context: any = null;
  constructor(notifyMethod: Function, notifyContext: any) {
    
    this.setNotifyMedthod(notifyMethod);
    this.setNotifyContext(notifyContext);
  }

  private getNotifyMethod(): Function {
  
    return this.notify;
  }

  setNotifyMedthod(notifyMedthod: Function): void {
    this.notify = notifyMedthod;
  }
  
  setNotifyContext(notifyContext: any): void {
    this.context = notifyContext;
  }

  private getNotifyContext(): any {
    
    return this.context;
  }

  notifyObserver(notification: INotification): void {

    this.getNotifyMethod().call(this.getNotifyContext(), notification);
  }

  compareNotifyContext(object: any): boolean {
    return object === this.context;
  }
}